<template>
	<view>
		<view class="addresstip">开奖后两天内未领取该奖品则视为自动放弃领奖，请您及时领奖</view>
		<view class="addresstitle">请选择收货地址</view>
		<navigator class="address" url="/pages/address/addresslist">
			<view class="addresslimit">
				送至 {{address}}
			</view>
			<view>›</view>
		</navigator>
		<view class="addresstitle">给发起人留意</view>
		<view class="content">
			<textarea :value="remark" @blur="blurarea" class="area" maxlength="50" placeholder="请输入留言信息,限制字（50字）！"></textarea>
		</view>
		<view class="duihuan" @click="addr">
			<view class="huan-button">保存</view>
		</view>
	</view>
</template>

<script>
	/**
	 * 中奖者填写收货地址
	 */
	export default {
		data() {
			return {
				address: '', //地址
				remark: '', //备注
				dreawid: '', //奖品ID
				ainfo:{},//地址
			}
		},
		onLoad(option) {
			if (option.id) {
				this.dreawid = option.id
			}
		},
		onShow() {
			this.ainfo = uni.getStorageSync('address');
			if (this.ainfo) {
				this.address = this.ainfo.realname + ',' + this.ainfo.phone + ',' + this.ainfo.area + this.ainfo.address;
			}
			console.log(this.$common.state); 
		},
		methods: {
			blurarea(e) {
				this.remark = e.detail.value;
			},

			addr() {
				if(!this.ainfo.id){
					this.$ShowMsg('收货地址不能为空！');
					return;
				}
				
				let  senddata ={
					id: this.dreawid,
					address_id: this.ainfo.id,
					remark: this.remark
				} 
				//console.log(senddata);
				//return;
				//添加后领取奖品
				this.$HttRequest({
					url: '/lottery/acceptPrize',
					param: senddata,
				},'POST',true).then((res) => {
					if (res.status === 10000) {
						//通知中奖者已填写地址
						this.$common.state.addreluckid = this.dreawid;
						
						//清除地址内存
						uni.removeStorageSync('address')
						//console.log(uni.getStorageSync('address'))
						this.$ShowMsg('领取成功！');
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1500)
					} else {
						this.$ShowMsg(res.message)
					}
				}).catch((error) => {
					//异常错误
					this.$ShowMsg('statusCode：' + error.errMsg);
				});
			}
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #f0f0f0;
	}

	.addresstip {
		font-size: 28rpx;
		flex: 1;
		background-color: #fff;
		padding: 20rpx;
		color: #333;
		margin-top: 20rpx;
	}

	.address {
		background-color: #fff;
		flex: 1;
		height: 80rpx;
		font-size: 28rpx;
		color: #333;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 20rpx;
	}

	.addresstitle {
		font-size: 25rpx;
		color: #333;
		padding-left: 20rpx;
		margin: 20rpx 0;
	}

	.content {
		flex: 1;
		padding: 20rpx;
		background-color: #fff;

		.area {
			height: 280rpx;
			margin-bottom: 30rpx;
			width: 100%;
			font-size: 28rpx;
		}
	}

	.addresslimit {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 680rpx;
	}

	.duihuan {
		background-color: #fff;
		border-top: 1rpx solid #d7d7d7;
		display: flex;
		width: 100vw;
		position: fixed;

		align-items: center;
		justify-content: center;
		bottom: 0;

		.huan-button {
			background-color: $uni-botton-primary;
			width: 92%;
			height: 85rpx;
			border-radius: 40rpx;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 30rpx;
			margin: 20rpx 0;
		}
	}
</style>
